#include<bits/stdc++.h>
using namespace std;
#define ERROR 0
#define OK 1
typedef int Status;
typedef struct LNode{
	int data;
	LNode *next;	
}LNode, *LinkList;

Status Create(LinkList &L, int n)
{
	L = new LNode;
	cin >> L->data;
	LNode *p, *pre = L;
	for(int i = 0; i < n - 1; i ++)
	{
		LNode *p = new LNode;
		cin >> p->data;
		pre->next = p;
		pre = p;
	}
	pre->next = L;
}
int Link(LinkList &h1, LinkList &h2)
{
	/*****************Begin*********************/
    LNode *p1 = h1->next;
	while(p1->next != h1)
	{
		p1 = p1->next;
	} 
	p1->next = h2;
	
	LNode *p2 = h2->next;
	while(p2->next != h2)
	{
		p2 = p2->next;
	} 
	p2->next = h1;
    /*****************End********************/
}
void Show(LinkList L)
{
	LNode *p = L;
	cout << L->data << ' ';
	p = L->next;
	while(p != L)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
int main()
{
	LinkList L1, L2;
	
	int n1, n2;
	cin >> n1 >> n2;
	Create(L1, n1);
	Create(L2, n2);
 
	Link(L1, L2);
	Show(L1);
	
	return 0; 
}